﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.BLL.Order;
using ECommerce.Model.Order;
using Jzy.Core.Common.Web;

namespace ECommerce.Web.ECAdmin.Order
{
    public partial class Export : PageDetail
    {
        private ECOrderBO Order
        {
            get
            {
                return ECOrderBO.Instance<ECOrderBO>();
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            ECOrderInfo info = Order.GetInfo(this.PKID);
            EntityUtil.SetControl(pnlMain, info);

            this.OrderID.Text = info.ID.ToString();
            this.PayState.Text = ((PayState)info.PayState).ToString();
            this.OrderState.Text = ((OrderState)info.OrderState).ToString();
            this.PayMode.Text = ((PayMode)info.PayMode).ToString();
            this.litArea.Text = ((BigArea)info.RecieveBigArea).ToString();
            this.litDeliverTime.Text = info.DeliverTime.ToString("yyyy-MM-dd");
            this.litFreight.Text = info.Freight.ToString("c2");
            this.litTotal.Text = (info.Freight + info.TradeValue).ToString("c2");
            //this.LogisticType.Text = this.LogisticsType.Text = ((LogisticType)info.LogisticsType).ToString();
            //if (info.InvoiceTarget == (int)InvoiceTarget.个人)
            //{
            //    this.InvoiceHead.Text = "个人";
            //}
            //else
            //{
            //    this.InvoiceHead.Text = info.InvoiceHead;
            //}

            rpt.DataSource = info.Products;
            rpt.DataBind();


            Response.AppendHeader("Content-Disposition", "attachment;filename=" + info.ID + ".xls");
            Response.Charset = "UTF-8";
            Response.ContentEncoding = System.Text.Encoding.Default;
            ContentType = "application/ms-excel";//image/JPEG;text/HTML;image/GIF;vnd.ms-excel/msword
            Page.EnableViewState = false;
            System.IO.StringWriter tw = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter hw = new System.Web.UI.HtmlTextWriter(tw);
            pnlMain.RenderControl(hw);
            Response.Write(tw.ToString());
            Response.End(); 
        }
    }
}